package cn.itlaobing.eshop.service;

import cn.itlaobing.eshop.dao.UserDao;
import cn.itlaobing.eshop.entity.Userinfo;
import cn.itlaobing.eshop.exception.BusinessException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;


import java.sql.SQLException;

/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/14 21:45
 */
public class UserService {

    public Userinfo findByUser(String account, String password) throws BusinessException {
        UserDao userDao=new UserDao();
        Userinfo userinfo=null;
        try {
            userinfo=userDao.findByUser(account,password);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return userinfo;
    }

    public int register(Userinfo userinfo)throws BusinessException {
        UserDao userDao=new UserDao();
        int r=0;

        try {
            r=userDao.register(userinfo);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return r;
    }
}
